<template>
  <el-config-provider :locale="locale">
    <router-view v-if="isRouterAlive" />
  </el-config-provider>
</template>

<script setup lang="ts">
import { computed, nextTick, provide, ref } from 'vue'

// import { ElConfigProvider } from 'element-plus'
import { useLocaleStore } from '@/store/locale'

import { localeMap } from '@/locales/config'
import en from 'element-plus/lib/locale/lang/en'
import zhCn from 'element-plus/lib/locale/lang/zh-cn'

const langObj = {
  [localeMap.zh_CN]: zhCn,
  [localeMap.en]: en,
}

const localeStore = useLocaleStore()

const locale = computed(() => {
  return langObj[localeStore.getLocale]
})

const isRouterAlive = ref(true)

const reload = () => {
  isRouterAlive.value = false
  nextTick(() => {
    isRouterAlive.value = true
  })
}

provide('reload', reload)
</script>
